package fr.psm.action;

import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

import fr.psm.bean.Personne;
import fr.psm.service.PersonneService;

public class PersonneAction implements Preparable {

	private PersonneService service;
	private Personne personne;
	private String id;
	private List<Personne> listPersonnes;

	public PersonneAction(PersonneService service) {
		this.service = service;
	}

	public String execute() {
		this.listPersonnes = service.findAll();

		return Action.SUCCESS;
	}

	public String save() {
		this.service.save(personne);
		this.personne = new Personne();
		return execute();
	}

	public String remove() {
		service.remove(id);
		return execute();
	}

	public void prepare() throws Exception {
		if (id != null)
			listPersonnes = service.findAll();
	}

	public List<Personne> getListPersonnes() {
		return listPersonnes;
	}

	public void setListPersonnes(List<Personne> listPersonnes) {
		this.listPersonnes = listPersonnes;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Personne getPersonne() {
		return personne;
	}

	public void setPersonne(Personne personne) {
		this.personne = personne;
	}
}
